<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <link rel="Shortcut Icon" href="../images/aecc.ico" type="image/x-icon" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <link href="../StaticFiles/element-plus-2.9.1/index.css" rel="stylesheet">
  <link href="../StaticFiles/nprogress/nprogress.min.css" rel="stylesheet">
  <link href="../styles/vue-page-common.css" rel="stylesheet">
  <script src="../Scripts/pollyfills/Array.prototype.flat.js"></script>
  <script src="../Scripts/pollyfills/ResizeObserver.js"></script>
  <script src="../StaticFiles/vue3/vue.global.prod.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/index.full.min.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/icons-vue.js"></script>
  <script src="../StaticFiles/element-plus-2.9.1/zh-cn.min.js"></script>
  <script src="../Scripts/axios.min.js"></script>
  <script src="../Scripts/axios.config.js"></script>
  <script src="../StaticFiles/nprogress/nprogress.min.js"></script>
  <script src="../Scripts/dayjs.min.js"></script>
  <script src="../Scripts/crypto-js.js"></script>
  <script src="../Scripts/secret.js"></script>
  <title>未完工序查询报表</title>
  <style>
    .el-table--large .cell {
      padding: 0 10px !important;
    }
  </style>
</head>

<body>
  <div id="app" v-cloak>
    <vue3-report-header title="未完工序查询报表"></vue3-report-header>
    <div style="padding: 10px;" @keyup.enter="getData">
      <!-- 查询条件区 -->
      <el-form :inline="true" :model="dataObj.queryInfo" ref="queryInfoRef" :label-position="'left'"
        :rules="dataObj.formRules">
        <el-form-item label="主制分厂:" prop="factoryid">
          <el-select style="width: 160px;" v-model="dataObj.queryInfo.factoryid" placeholder="请选择主制分厂" clearable
            :disabled="dataObj.factoryDisabled" filterable @change="selectChange">
            <el-option v-for="f in dataObj.factoryList" :key="f.factoryid" :label="f.factoryname" :value="f.factoryid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="工区:">
          <el-select style="width: 160px;" v-model="dataObj.queryInfo.workcenterid" placeholder="请选择工区" clearable
            filterable>
            <el-option v-for="f in dataObj.workcenterList" :key="f.workcenterid" :label="f.workcentername"
              :value="f.workcenterid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item label="订单号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.mfgordername" placeholder="请输入订单号" :trigger-on-focus="false"
            :fetch-suggestions="searchMfgorderAsync" :value-key="'mfgordername'" :debounce="500" style="width:200px;">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="零件图号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.productname" placeholder="请输入零件图号" :trigger-on-focus="false"
            style="width:200px;" :fetch-suggestions="searchProductAsync" :value-key="'productname'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="批次号:">
          <el-autocomplete v-model.trim="dataObj.queryInfo.containername" placeholder="请输入批次号" :trigger-on-focus="false"
            style="width:280px;" :fetch-suggestions="searchContainerAsync" :value-key="'containername'" :debounce="500">
          </el-autocomplete>
        </el-form-item>

        <el-form-item label="订单计划完成时间:" prop="plannedcompletiondate">
          <el-date-picker v-model="dataObj.queryInfo.plannedcompletiondate" type="daterange" range-separator="至"
            start-placeholder="开始日期" end-placeholder="结束日期" value-format="YYYY-MM-DD" :shortcuts="dataObj.shortcuts"
            style="width: 220px;">
          </el-date-picker>
        </el-form-item>

        <el-form-item label="计划员:">
          <el-select v-model="dataObj.queryInfo.jihuayuan" placeholder="请选择" clearable filterable style="width: 140px;">
            <el-option v-for="p in dataObj.jihuayuanList" :key="p.employeeid" :label="p.fullname" :value="p.employeeid">
            </el-option>
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" :icon="'Search'" size="default" @click="getData">查询</el-button>
          <el-button type="primary" :icon="'Download'" size="default" @click="getExportExcel">导出</el-button>
        </el-form-item>
      </el-form>

      <!-- 表格 -->
      <el-table :data="dataObj.dataList" stripe border show-overflow-tooltip v-loading.fullscreen.lock="dataObj.loading"
        :element-loading-text="dataObj.loadingText" element-loading-background="rgba(0,0,0,0.8)">
        <el-table-column type="index" width="60"></el-table-column>
        <el-table-column prop="factoryname" label="主制分厂" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="mfgordername" label="订单号" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="plannedstartdate" label="订单计划开始时间" width="100" :formatter="splitDate"></el-table-column>
        <el-table-column prop="plannedcompletiondate" label="订单计划完成时间" width="100" :formatter="splitDate">
        </el-table-column>
        <el-table-column prop="fullname" label="计划员" width="80" show-overflow-tooltip>
          <template #header>
            <span>计划员</span>
            <el-tooltip placement="top">
              <template #content>开卡人</template>
              <el-icon style="margin-left:5px;">
                <info-filled />
              </el-icon>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="containername" label="流水卡号" width="200" show-overflow-tooltip></el-table-column>
        <el-table-column prop="qty" label="计划数量" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productname" label="零件图号" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productdescription" label="物料描述" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="productrevision" label="零件版本" width="50" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowname" label="工艺路线" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowrevision" label="工艺版本" width="50" show-overflow-tooltip></el-table-column>
        <el-table-column prop="specno" label="工序号" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflowstepname" label="工序名称" width="80" show-overflow-tooltip></el-table-column>
        <el-table-column prop="makeempcounts" label="作业人数" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workcentername" label="工区" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="teamname" label="班组" width="100" show-overflow-tooltip></el-table-column>
        <el-table-column prop="makecycle" label="加工工时" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="preparecycle" label="准备工时" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="transfercycle" label="转运工时" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="resourcelist" label="设备" width="120" show-overflow-tooltip></el-table-column>
        <el-table-column prop="shipcycle" label="转工周期" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="commicycle" label="外委周期" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="chargingqty" label="装炉/槽量" width="60" show-overflow-tooltip></el-table-column>
        <el-table-column prop="workflow_createdate" label="工艺创建时间" width="80" show-overflow-tooltip>
          <template #header>
            <span>计划员</span>
            <el-tooltip placement="top">
              <template #content>该字段当前内容为空</template>
              <el-icon style="margin-left:5px;">
                <info-filled />
              </el-icon>
            </el-tooltip>
          </template>
        </el-table-column>
        <el-table-column prop="step_type" label="工序类型" width="80" show-overflow-tooltip>
          <template #header>
            <span>工序类型</span>
            <el-tooltip placement="top">
              <template #content>该字段当前内容为空</template>
              <el-icon style="margin-left:5px;">
                <info-filled />
              </el-icon>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>

      <!-- 分页 -->
      <el-pagination @size-change="handleSizeChange" @current-change="handleCurrentChange"
        :current-page="dataObj.currentPage" :page-sizes="[dataObj.pageSize,20,50]" :page-size="dataObj.pageSize"
        layout="prev,pager,next,jumper,sizes,total" :total="dataObj.total">
      </el-pagination>

      <!-- 回到顶部 -->
      <el-backtop></el-backtop>
    </div>
  </div>
  <script type="module">
    import Vue3ReportHeader from '../Scripts/components/Vue3ReportHeader.js';
    import { exportExcel, getFactory, fetchSuggestion, getParams } from '../Scripts/hooks/useCommonMethod.js'
    import { splitDate, replaceDate } from '../Scripts/hooks/format.js'
    import { getUserInfo, getFactoryUsersByRoleName, getWorkcenterList } from '../Scripts/hooks/fetchAPI.js'
    import { prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth } from '../Scripts/hooks/vue3DateShortCut.js'
    const { createApp, reactive, ref, onMounted, watch } = Vue
    const { ElMessage } = ElementPlus
    const App = {
      setup() {
        const queryInfoRef = ref(null);
        const dataObj = reactive({
          loading: false,
          loadingText: '数据加载中...',
          currentPage: 1,// 当前页
          pageSize: 12, // 每页显示条数
          total: 0,
          queryInfo: {
            factoryid: '',
            productname: '',
            containername: '',
            mfgordername: '',
            plannedcompletiondate: '',
            jihuayuan: ''
          },
          factoryDisabled: false,
          dataList: [],
          factoryList: [],
          workcenterList: [],
          jihuayuanList: [],
          formRules: {
            factoryid: [
              { required: true, message: '【主制分厂】不能为空', trigger: 'change' },
            ]
          },
          shortcuts: [prevWeek, thisWeek, nextWeek, prevMonth, thisMonth, nextMonth]
        })

        const api = '../handler/report/UncheckWorkflowstepReport.ashx'

        function searchContainerAsync(value, callback) {
          fetchSuggestion({ actionName: 'getContainernameAsync', name: 'containername', value, callback })
        }

        function searchProductAsync(value, callback) {
          fetchSuggestion({ actionName: 'getProductnameAsync', name: 'productname', value, callback });
        }

        function searchMfgorderAsync(value, callback) {
          fetchSuggestion({ actionName: 'getMfgordernameAsync', name: 'mfgordername', value, callback });
        }

        // 查询数据
        async function getData() {
          const valid = await queryInfoRef.value.validate(valid => valid);
          if (!valid) return;

          dataObj.loading = true;
          dataObj.loadingText = '数据加载中...';
          const { data: { data, meta, total } } = await axios({
            url: `${api}?actions=getData`,
            method: 'post',
            data: {
              ...dataObj.queryInfo,
              currentPage: dataObj.currentPage,
              pageSize: dataObj.pageSize,
              type: 'getData'
            }
          })
          dataObj.loading = false
          if (meta.status === 500) {
            return ElMessage.error(meta.msg);
          }
          dataObj.dataList = data;
          dataObj.total = total;
        };

        // 导出excel
        async function getExportExcel() {
          const valid = await queryInfoRef.value.validate(valid => valid);
          if (!valid) return;
          const config = {
            url: `${api}?actions=exportExcel`,
            data: { ...dataObj.queryInfo, type: 'exportExcel' }
          }
          exportExcel(config, dataObj, ElMessage)
        };

        function handleCurrentChange(newPage) {
          dataObj.currentPage = newPage;
          getData();
        };

        function handleSizeChange(newSize) {
          dataObj.pageSize = newSize;
          getData();
        };

        async function selectChange() {
          if (dataObj.queryInfo.factoryid) {
            const { factoryid } = dataObj.queryInfo;
            dataObj.queryInfo.jihuayuan = '';
            dataObj.queryInfo.workcenterid = '';
            dataObj.jihuayuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '计划员' });
            dataObj.workcenterList = await getWorkcenterList({ factoryid });
          }
        }

        onMounted(async () => {
          const start = dayjs().startOf('week').add(1, 'day').subtract(7, 'day').format('YYYY-MM-DD');
          const end = dayjs().endOf('week').add(1, 'day').subtract(7, 'day').format('YYYY-MM-DD');
          dataObj.queryInfo.starttime = [start, end];

          const [factoryinfo, userInfo] = await Promise.all([
            getFactory(dataObj),
            getUserInfo({ employeeid: getParams("uid") })
          ]);

          if (userInfo && userInfo.factorycode) {
            const factory = dataObj.factoryList.filter(item => item.factorycode === userInfo.factorycode)
            const { factoryid } = factory[0]
            dataObj.factoryList = factory;
            dataObj.queryInfo.factoryid = factoryid;
            dataObj.factoryDisabled = true;
            dataObj.jihuayuanList = await getFactoryUsersByRoleName({ factoryid, rolename: '计划员' });
            dataObj.workcenterList = await getWorkcenterList({ factoryid });
          }
        })

        watch(() => dataObj.queryInfo, () => {
          dataObj.currentPage = 1;
        }, { deep: true })

        return {
          dataObj, splitDate, replaceDate,
          getData,
          getExportExcel,
          handleCurrentChange,
          handleSizeChange,
          searchContainerAsync,
          searchProductAsync,
          searchMfgorderAsync,
          queryInfoRef,
          selectChange
        }
      }
    };

    const app = createApp(App);
    app.use(ElementPlus, {
      locale: ElementPlusLocaleZhCn,
      size: 'large'
    });
    // 注册所有icon
    for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
      app.component(key, component)
    }
    app.component('vue3-report-header', Vue3ReportHeader);
    app.mount('#app');
  </script>
</body>

</html>